package com.yathit.sync.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.http.client.URL;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Anchor;

public class GadgetPanel extends Composite {
	
	private String ownerName;

	private static GadgetPanelUiBinder uiBinder = GWT
			.create(GadgetPanelUiBinder.class);
	@UiField Label lblGroupName;
	@UiField Anchor linkInvite;

	interface GadgetPanelUiBinder extends UiBinder<Widget, GadgetPanel> {
	}

	public GadgetPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		
		linkInvite.setHref(composeInvitationUrl("you@home.com", "Zaw", "Yathit shared"));
	}
	
	private String composeInvitationUrl(String toEmail, String toName, String groupLabel) {
		StringBuilder sb = new StringBuilder();
		sb.append("https://mail.google.com/mail/?view=cm&fs=1&tf=1");
		sb.append("&to=" + toEmail);
		sb.append("&su=" + "Gmail contacts shared by " + ownerName);
		sb.append("&body=" + "Hi " + toName + "!\n");
		sb.append("I have shared my contact list " + groupLabel + ". Click here to synchronize the contacts in your Gmail contacts.");
		sb.append("Yours,\n" + ownerName);
		
		return URL.encode(sb.toString());
	}

}
